package com.ruoyi.project.wx.carInfo.controller;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.user.domain.User;
import com.ruoyi.project.wx.carInfo.domain.CarInfo;
import com.ruoyi.project.wx.carInfo.service.CarInfoService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/wx/carInfo")
public class CarInfoController extends BaseController {

    @Autowired
    private CarInfoService carInfoService;

    private String prefix = "wx/carInfo";

    @RequiresPermissions("wx:carInfo:view")
    @GetMapping()
    public String toCarInfoList()
    {
        return prefix + "/list";
    }

    @RequiresPermissions("wx:carInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarInfo carInfo) {
        startPage();
        List<CarInfo> carInfoList = carInfoService.carInfolist(carInfo);
        return getDataTable(carInfoList);
    }

    /**
     * 修改
     */
    @RequiresPermissions("wx:carInfo:update")
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult update(CarInfo carInfo)
    {
        return toAjax(carInfoService.update(carInfo));
    }

    @RequiresPermissions("wx:carInfo:remove")
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        try
        {
            return toAjax(carInfoService.delCarInfoByIds(ids));
        }
        catch (Exception e)
        {
            return error(e.getMessage());
        }
    }

    /**
     * 修改用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        mmap.put("carInfo", carInfoService.selectCarInfoById(id));
        return prefix + "/edit";
    }

    /**
     * 修改保存用户
     */
    @RequiresPermissions("wx:carInfo:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarInfo carInfo)
    {
        return toAjax(carInfoService.update(carInfo));
    }

}
